//
//  UserStorage.m
//  DailyRecord
//
//  Created by Gin on 2022/3/28.
//

#import "UserStorage.h"

#define kUserKey  @"user"

@implementation UserStorage

+ (User * _Nullable)loadUser{
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    NSData *userData = [df objectForKey:kUserKey];
    if (!userData) {
        return nil;
    }
    NSError *error = nil;
    NSDictionary *userDic = [NSJSONSerialization JSONObjectWithData:userData options:NSJSONReadingMutableContainers error:&error];
    if (error) {
        return nil;
    }
    User *user = [User yy_modelWithJSON:userDic];
    return user;
}

+ (void)storeUser:(NSData * _Nullable)userData{
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    [df setObject:userData forKey:kUserKey];
    [df synchronize];
}

@end
